from apps.news import news_pb2, news_pb2_grpc
from apps.news.models import KrNews


class NewsService(news_pb2_grpc.NewsServicer):

    def NewsSearch(self, request, context):
        print("in..... news search")
        query = request.query
        page = request.page
        page_size = request.page_size
        news_objs = KrNews.objects.all()[:3]
        results = []
        for news in news_objs:
            item = dict()
            item['id'] = news.id
            item['title'] = news.title
            results.append(item)

        return news_pb2.NewsSearchResult(results=results)